//
//  CGalleryView.h
//  HCHK_iphone
//
//  Created by yilong zhang on 11-12-7.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "CProduct.h"

#define ITEM_WIDTH      50
#define ICON_WIDTH      104
#define ICON_HEIGHT     128
#define FOUCS_WIDTH     50
#define FOUCS_HEIGHT    50

@class CGalleyItem;

@protocol GalleryItemDelegate <NSObject>

@optional
-(void)DidGalleryItemSelected:(CGalleyItem*)item;

@end

@interface CGalleyItem : UIView

@property (nonatomic, assign) id<GalleryItemDelegate>   m_delegate;

@property (nonatomic, assign) int            m_nTag;
@property (nonatomic, assign) UIImageView    *m_ImageView;

-(id)initWithImage:(UIImage*)image;
-(void)SetPosition:(CGRect)position;
-(void)SetSelected;

@end

typedef enum {ScrollLeft, ScrollRight} ScrollMoveDirectory;

@protocol GalleryDelegate <NSObject>

@optional
-(void)DidGallerySelected:(int)index Directory:(int)directory Object:(id)object;
-(void)DidGalleryTurnPage:(int)index Directory:(int)directory Object:(id)object;
-(void)DidGalleryBottom:(id)object;
-(void)DidGalleryDragEnd:(id)object;

@end


@interface CGalleryView : UIView<GalleryItemDelegate, UIScrollViewDelegate>

@property (nonatomic, assign) id<GalleryDelegate>   m_delegate;

@property (nonatomic, assign) BOOL              m_bIsHorizontal;
@property (nonatomic, assign) UIScrollView      *m_RootScroll;
@property (nonatomic, assign) BOOL              m_bIsDrag;
@property (nonatomic, assign) CGPoint           m_ScrollOffset;
@property (nonatomic, assign) UIView            *m_RootPanel;
@property (nonatomic, assign) UIView            *m_FocusPanel;
@property (nonatomic, assign) int               m_nOldFocus;
@property (nonatomic, assign) UIImageView       *m_FocusView;
@property (nonatomic, assign) int               m_nPages;
@property (nonatomic, assign) int               m_nItemsNum;
@property (nonatomic, assign) int               m_nPageItems;
@property (nonatomic, assign) BOOL              m_bIsPageEnd;
@property (nonatomic, assign) int               m_nStartIndex;

//new
@property (nonatomic, assign) CGPoint               m_OldOffset;        //oldposition
@property (nonatomic, assign) ScrollMoveDirectory   m_nMoveDirection;   //0left,1right
@property (nonatomic, retain) NSMutableArray        *m_ItemsData;

@property (nonatomic, assign) UIView                  *m_IndicatorView;
@property (nonatomic, assign) UIActivityIndicatorView *m_Indicator;

-(id)initWithFrame:(CGRect)frame ItemSize:(CGSize)itemsize Horizontal:(BOOL)horizontal;
-(void)InitGalleryView:(CGRect)frame ItemSize:(CGSize)itemsize Horizontal:(BOOL)horizontal;
-(int)SetItems:(NSArray*)items Item:(CGalleyItem*)item;
-(void)GetGalleryPages;
-(void)DidSelected:(int)index;
-(void)SetFocusPosition:(int)index;
-(void)UpdateScrollOffset;
-(void)ResetGallery;
-(void)ResetLoyout:(UIInterfaceOrientation)inerfaceorientation;

//new
-(void)CorrectScrollViewPosition:(UIScrollView*)scrollView;
-(void)ShowIndicator;
-(void)HiddenIndicator;

@end
